//
//  XLUserCenterAdapter.m
//  industry
//
//  Created by xl on 2020/11/24.
//  Copyright © 2020 Haier. All rights reserved.
//

#import "XLUserCenterAdapter.h"
#import "XLUserCenterTitleHeaderView.h"
#import "XLUserCenterDataCell.h"
#import "XLIconTitleArrowCell.h"
#import "XLUserCenterInteractorProtocol.h"

NSString *const XLUserCenterAdapterCommonProblem = @"XLUserCenterAdapterCommonProblem";
NSString *const XLUserCenterAdapterAccountProblem = @"XLUserCenterAdapterAccountProblem";
NSString *const XLUserCenterAdapterAboutUs = @"XLUserCenterAdapterAboutUs";

@implementation XLUserCenterAdapter

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 1;
    }
    return self.getAdapterArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 45.0f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.01;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    XLUserCenterTitleHeaderView *headeView = [[XLUserCenterTitleHeaderView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 45)];
    if (section == 0) {
        [headeView loadHeaderViewTitle:@"我的资料"];
    } else {
        [headeView loadHeaderViewTitle:@"其他"];
    }
    return headeView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        return 72.0f;
    }
    return 60.0f;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        static NSString *cellIdentifierId = @"XLUserCenterDataCell";
        XLUserCenterDataCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifierId];
        if (!cell) {
            cell = [[XLUserCenterDataCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifierId];
        }
        cell.cardBlock = ^{//点击名片小程序
            if (self.cardModel) {
                XLSend(tableView.baseController.interactor, XLUserCenterInteractorProtocol, gotoAppletVC:self.cardModel);
            }
        };
        cell.archiveBlock = ^{//点击个人资料小程序
            if (self.archiveModel) {
                XLSend(tableView.baseController.interactor, XLUserCenterInteractorProtocol, gotoAppletVC:self.archiveModel);
            }
        };
        return cell;
    }
    if (indexPath.row > self.getAdapterArray.count - 1) {
        return [XLTableViewCell new];
    }
    static NSString *cellIdentifierId = @"XLIconTitleArrowCell";
    id cellData = self.getAdapterArray[indexPath.row];
    XLIconTitleArrowCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifierId];
    if (!cell) {
        cell = [[XLIconTitleArrowCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifierId];
    }
    if ([cellData isEqualToString:XLUserCenterAdapterCommonProblem]) {
        [cell loadCellData:@"cjwt" title:@"常见问题" info:@""];
    } else if ([cellData isEqualToString:XLUserCenterAdapterAccountProblem]) {
        [cell loadCellData:@"zhaq" title:@"账户安全" info:@""];
    } else if ([cellData isEqualToString:XLUserCenterAdapterAboutUs]) {
        [cell loadCellData:@"gywm" title:@"关于我们" info:@""];
    }
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        return;
    }
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    if (indexPath.row > self.getAdapterArray.count - 1) {
        return;
    }
    id cellData = self.getAdapterArray[indexPath.row];
    if (self.adapterDelegate && [self.adapterDelegate respondsToSelector:@selector(didSelectCellData:)]) {
        [self.adapterDelegate didSelectCellData:cellData];
    }
}

@end
